//
//	File: D3D9Camera.h
//

#ifndef OYDIRECT3D9_CAMERA_H
#define OYDIRECT3D9_CAMERA_H

#include <windows.h>
#include "../../OyRenderer/OyEngine.h"
#include "../../OyMath3D/OyMath3D.h"
#include "../../OyGeneral/OyGeneral.h"


class OyD3D9Camera
{
public:
	float           m_fNear;             // near clipping plane
	float           m_fFar;              // far clipping plane
    OY_CAMERAMODE   m_Mode;              // persp., ortho or 2d
	OY_VIEWPORT     m_ViewPort;
	OyVector4D		m_CameraPos;		 // camera position

    OyMatrix		m_mViewMatrix;       // view matrix
    OyMatrix        m_mProjMatrix;       // projection matrix perspective
	OyMatrix		m_mViewProjMatrix;


public:
	void	SetClippingPlanes(float fNear, float fFar);
	void	SetViewMatrix3D(const OyVector4D& vcRight, const OyVector4D& vcUp, 
							const OyVector4D& vcDir, const OyVector4D& vcEyePos);

	void	GetFrustrum(OyPlane *p);
	float*	GetPos() { return (float*)&m_CameraPos; }
	void	GetViewMatrix(float *p) { memcpy(p, &m_mViewMatrix, sizeof(OyMatrix)); } 
	void	GetProjMatrix(float *p) { memcpy(p, &m_mProjMatrix, sizeof(OyMatrix)); }

    HRESULT CalcPerspProjMatrix(float fFOV, float fAspect);
    HRESULT CalcOrthoProjMatrix(float l, float r, float b, float t, float fN, float fF);
	HRESULT CalcOrthoProjMatrix(float w, float h, float fN, float fF);

private:
	void    Prepare2DMode(void);
	void    CalcViewProjMatrix(void) { m_mViewProjMatrix = m_mViewMatrix * m_mProjMatrix; }
};

#endif